package byx.container.annotation.demo.StrategyDemo.a;

import byx.container.annotation.annotation.Register;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Register
public class StrategyRunnerImpl implements StrategyRunner {
    private final Map<String, Strategy> strategyMap;

    public StrategyRunnerImpl(List<Strategy> strategies) {
        strategyMap = strategies.stream()
                .collect(Collectors.toMap(
                        Strategy::id,
                        s -> s
                ));
    }

    @Override
    public String run(String id, String input) {
        return strategyMap.get(id).handle(input);
    }
}
